package com.example.home.logistics.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.home.R;
import com.example.home.logistics.adapter.ComplaintListAdapter;
import com.example.home.logistics.bean.ComplaintListBean;
import com.example.home.tool.OKHttpTool;

public class ComplaintDetails extends AppCompatActivity {
    private ImageView back;
    private ImageView add;
    private RecyclerView rcvList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_complaint_details);
        Intent intent = getIntent();
        String companyId = intent.getStringExtra("companyId");
        String infoNo = intent.getStringExtra("infoNo");
        String name = intent.getStringExtra("name");


        back = findViewById(R.id.back);
        add = findViewById(R.id.add);
        rcvList = findViewById(R.id.rcv_list);

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ComplaintDetails.this.finish();
            }
        });

        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent(ComplaintDetails.this,AddComplaintActivity.class);
                intent1.putExtra("companyId",String.valueOf(companyId));
                intent1.putExtra("infoNo",String.valueOf(infoNo));
                intent1.putExtra("name",String.valueOf(name));
                startActivity(intent1);
            }
        });

        getComplaintList();
    }

    @Override
    protected void onResume() {
        super.onResume();
        getComplaintList();
    }

    private void getComplaintList() {
        OKHttpTool.doNetRequest("prod-api/api/logistics-inquiry/logistics_complaint/my-list",
                OKHttpTool.GET,
                ComplaintListBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        ComplaintListBean complaintListBean = (ComplaintListBean) obj;
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                bindList(complaintListBean);
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                }
        );
    }

    private void bindList(ComplaintListBean complaintListBean) {
        ComplaintListAdapter complaintListAdapter = new ComplaintListAdapter(ComplaintDetails.this,complaintListBean.getRows());
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(ComplaintDetails.this);
        rcvList.setAdapter(complaintListAdapter);
        rcvList.setLayoutManager(linearLayoutManager);
    }
}